package com.cat.chapter035;

import java.io.*;
import java.util.HashMap;

/**
 * @author cat
 * @description
 * @create 2025/5/29 20:11
 * @since JDK17
 */

public class Code01SetAllMap {
    private static HashMap<Integer, int[]> map = new HashMap<>();
    private static int setAllValue; // 所有值
    private static int setAllTime;  // 时间戳
    private static int cnt;         // 当前时间
    private static int n;         // 命令数
    private static int op;         // 当前操作
    private static int a;
    private static int b;

    public static void put(int a, int b) {
        map.put(a, new int[]{b, cnt++});
    }

    public static void setAll(int a) {
        setAllValue = a;
        setAllTime = cnt++;
    }

    public static int get(int a) {
        int[] ints = map.get(a);
        if (ints == null) {
            return -1;
        }

        if (ints[1] > setAllTime) {
            return ints[0];
        } else {
            return setAllValue;
        }
    }

    public static void main(String[] args) throws IOException {
        // 读数据
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // 分类
        StreamTokenizer in = new StreamTokenizer(br);
        // 打印
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            map.clear();    // 清空哈希表
            setAllValue = 0;
            setAllTime = -1;
            cnt = 0;
            n = (int) in.nval;
            for (int i = 0; i < n; i++) {
                in.nextToken();
                op = (int) in.nval;

                if (op == 1) {  // 设置
                    in.nextToken();
                    a = (int) in.nval;
                    in.nextToken();
                    b = (int) in.nval;
                    put(a, b);
                } else if (op == 2) {   // 获取
                    in.nextToken();
                    a = (int) in.nval;
                    out.println(get(a));
                } else {    // 所有数一起设置
                    in.nextToken();
                    a = (int) in.nval;
                    setAll(a);
                }
            }
        }
        out.flush();
        out.close();
        br.close();
    }

}
